from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsRole(Base):
    __tablename__ = 'cms_role'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='_copy_20'),
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    role_id: Mapped[str] = mapped_column(String(32), comment='角色编码')
    role_name: Mapped[str] = mapped_column(String(64), comment='角色名称')
    sort: Mapped[int] = mapped_column(Integer, comment='排序（0-99，默认0，越大越靠前）')
    state: Mapped[int] = mapped_column(Integer, comment='状态（0 失效，1 有效）')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime)
    illustrate: Mapped[Optional[str]] = mapped_column(String(255), comment='角色说明')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime)
